package com.example.demo.calc;

import com.google.common.hash.HashCode;

public class BinaryTransfor {

    public static void main(String[] args) {
        /**
         * 十进制转二进制
         */
        for (int i = 0; i < 10; i++) {
            String string = Integer.toBinaryString(i + 1);
            int anInt = Integer.parseInt(string);
            System.out.println(String.format("%04d",anInt));
        }
        System.out.println("====================");
        /**
         * 十六进制转二进制
         * 十六进制表示：1 2 3 4 5 6 7 8 9 a b c d e f
         */
        String hexString = "4D";
        int i = Integer.parseInt(hexString, 16);
        System.out.println(i);
        String string = Integer.toBinaryString(i);
        System.out.println(string);
        System.out.println("====================");
        // B4-D5-BD-93-91-2B
        System.out.println(4+11*16+5+13*16+13+11*16+3+9*16+1+9*16+11+2*16);
        String str = Integer.toBinaryString(917);
        System.out.println(str);
        String value = "B4";
        int binary = Integer.parseInt(value, 16);
        String str2 = Integer.toBinaryString(binary);
        System.out.println(str2);
    }


}
